﻿using BLL;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using 纺织贸易管理系统.设置窗体;

namespace 后整理管理系统.数据分析
{
    public partial class 进仓日报表 : Form
    {
        private DateTime QueryDate = DateTime.Now;
        public 进仓日报表()
        {
            InitializeComponent();
        }
        private void query()
        {

            this.ShowWaitForm("正在生产报表，请等待.............");
            chart1.Series.Clear();
            gridControl1.DataSource = 当月进仓报表.CreateReport(QueryDate);
            gridControl2.DataSource = 当月进仓报表.CreateCustomerReport(QueryDate);
            var dt = gridControl1.DataSource as DataTable;
            var series = new Series("进仓数");
            series.ChartType = SeriesChartType.Line;
            // 设置悬停提示格式
            series.ToolTip = "日期: #VALX\n数量: #VALY";  // 使用内置变量占位符
                                                      //series.IsValueShownAsLabel = false;  // 关闭默认标签显示
                                                      // 绑定数据
            foreach (DataRow row in dt.Rows)
            {
                series.Points.AddXY(
                    row["日期"].ToString(),
                    row["米数"]);
            }
            chart1.Series.Add(series);
            this.HideWaitForm();

        }

        private void 进仓日报表_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 10; i++)
            {
                comboBox1.Items.Add(DateTime.Now.Year - i);
            }
            comboBox1.Text = DateTime.Now.Year.ToString();
            comboBox2.Text = DateTime.Now.Month.ToString();
            QueryDate = DateTime.Parse(comboBox1.Text + "-" + comboBox2.Text + "-01");
            query();
        }

        private void gridView1_Click(object sender, EventArgs e)
        {
            this.Invoke(new MethodInvoker(() =>
            {
                gridControl3.DataSource = 当月进仓报表.CreateCustomerDetailReport(DateTime.Parse(comboBox1.Text + "-" + comboBox2.Text + "-" + gridView1.GetFocusedRowCellValue("日期")));
            }));
        }

        private void uiComboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            QueryDate = DateTime.Parse(comboBox1.Text + "-" + comboBox2.Text + "-01");
            query();
        }

        private void uiSymbolButton1_Click(object sender, EventArgs e)
        {
            ExportFile.导出到文件(gridControl3, "生产进仓日报表");
        }
    }
}
